package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.entity.CommonResult;
import com.atguigu.springcloud.entity.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @Author lizhilong
 * @create 2020/4/29 22:07
 * @desc
 */
@Slf4j
@RestController
public class OrderController {

    public static  final String url_prefix = "http://CLOUD-PAYMENT-SERVICE";

    @Resource
    private RestTemplate restTemplate;

    @GetMapping("/consumer/order/create")
    public CommonResult<Integer> create(@RequestBody Payment payment){
        CommonResult commonResult = restTemplate.postForObject(url_prefix + "/payment/create", payment, CommonResult.class);
        return commonResult;
    }

    @GetMapping("/consumer/payment/get/{id}")
    public CommonResult<Payment> get(@PathVariable("id") Integer id){
        CommonResult commonResult = restTemplate.getForObject (url_prefix + "/payment/get/"+id, CommonResult.class);
        return commonResult;
    }
}
